package cn.edu.scau.cmi.liyunlin.adapter;

import java.util.List;

public class SortUtil {
	
	public List sort(List<Student> studentList, int low, int high) {
		
		int i, j;
		Student t, temp;
		
		if(low > high) {
			return studentList;
		}
		i = low;
		j = high;
		temp = studentList.get(low);
		
		while( i < j) {
			while( temp.getId() <= studentList.get(j).getId() && i < j) {
				j--;
			}
			while( temp.getId() >= studentList.get(i).getId() && i < j) {
				i++;
			}
			
			if( i < j ) {
				t = studentList.get(j);
				studentList.set(j, studentList.get(i));
				studentList.set(i, t);
			}
		}
		
		studentList.set(low, studentList.get(i));
		studentList.set(i, temp);
		
		sort( studentList, low, j-1);
		sort( studentList, j+1, high);
		
		return studentList;
	}
	
}
